<template>
	<view class="content">
			
			<view class="userback">
				<image :src="adminPic"></image>
				<view class="userName">{{adminName}}</view>
			</view>
			<view class="menu">	
				<uni-list>
					<uni-list-item title="操作记录" showArrow
										thumb="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png"
										thumb-size="sm" rightText="详情" :to="toHistory"/>					
					<uni-list-item :show-extra-icon="true" showArrow :extra-icon="extraIcon" title="个人资料" @click="toSetting" link/>
				</uni-list>	
			</view>		
			<view class="btn-row">
				<button type="primary" class="primary" @tap="bindLogout">退出登录</button>
			</view>
		</view>
</template>

<script>
	export default {
		data() {
			return {
				// apiUrl:"http:// 10.133.149.97:8080/",
				apiUrl:"http://localhost:8080/",
				adminUid:0,  //待完善
				adminPic:"/static/管理员.png",
				adminName:"未登录",
				toHistory:"/pages/admin/history",
				extraIcon: {
					color: '#4cd964',
					size: '22',
					type: 'gear-filled',
					}
			}
		},
		onShow() {
			this.login();
		},
		methods: {
			login() {
				uni.request({
					method:'GET',
					url:this.apiUrl+'user/token',
					header:{
							Authorization : uni.getStorageSync("token")
						},
					success: (res) => {
						console.log(res.data);
						this.adminUid=res.data.uid;
						console.log(this.adminUid);
						this.adminName=res.data.name;
						this.adminPic=res.data.picture;
					},
					fail: (err) => {
									return uni.showToast({
										icon: 'loading',
										title:'请求失败'
									})
									reject(err)
								}
				})
			},
			bindLogout(){
				/* this.adminName="未登录";
				this.adminPic="";
				this.adminUid=0; */
				uni.clearStorageSync();
				uni.reLaunch({
					url:"/pages/login/login"
				})
			},
			toSetting(){
				uni.navigateTo({
					url: "/pages/admin/admin-setting"+'?uid='+this.adminUid
				})
			}
		}
	}
</script>

<style>
	.userback {
			height: 216px;
			background-image: url('/static/th.jpg');
			background-repeat: no-repeat;
			background-size: 100%;
			text-align: center
		}
	
		.userback image {
			margin: auto;
			border-radius: 51px;
			margin-top: 10%;
			width: 97px;
			height: 97px;
		}
		.userName{
			color: #111111;
			font-size: 0.9rem;
		}	
		.menu{
			padding-top: 25rpx;
		}
		uni-button {
			position:fixed;
			bottom:15rpx;
			width:90%;
		    margin: 15% 4%;
		    background: #2979ff;
		    color: #fff; 
		}
</style>
